<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMapAsync"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :defaultEventKey="defaultEventKey"
      :labelWidth="80"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>w-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
      :defaultEventKey="defaultEventKey"
      :randomRowKey="true"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="120" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
                {
                  label: '应答明细',
                  visible: scope.row.rspId!==null&&scope.row.rspId!==undefined,
                  doFunc: () => {
                    handleAction('answerdetail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="120px">
        <el-card class="form-card txnInfo-card">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailForm.id" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="报文标识号" prop="pkgId">
              <el-input v-model="detailForm.pkgId" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker
                v-model="detailForm.workdate"
                style="width: 100%"
                type="date"
                value-format="yyyyMMdd"
                :disabled="true"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="扣款管理类型" prop="dbtMngType">
              <el-select
                style="width: 100%"
                v-model="detailForm.dbtMngType"
                placeholder="扣款管理类型"
                :disabled="true"
              >
                <el-option
                  v-for="dict in dictMap.DebitManagementTypeCode"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="扣款通知编号" prop="dbtNo">
              <el-input v-model="detailForm.dbtNo" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="地域标识" prop="regionId">
              <el-select style="width: 100%" v-model="detailForm.regionId" placeholder="地域标识" :disabled="true">
                <el-option
                  v-for="dict in dictMap.RegionId"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="统一社会信用代码" prop="uniformScCode">
              <el-input v-model="detailForm.uniformScCode" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="付款人数目" prop="payerNum">
              <el-input v-model="detailForm.payerNum" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
          <div class="discountReceipt-pick-operate-box">
            <div class="operate-box-bottom">
              <div class="bottom-content">
                <ht-table
                  ref="dataTableDetail"
                  :multi-select="false"
                  :showSerialNumber="false"
                  :dictMap="dictMap"
                  :queryParams="queryParamsDetail"
                  :tableBindColumns="tableBindColumnsDetail"
                  :opButtonList="opButtonList"
                  :reqConfig="regConfigDetail"
                  :showRightToolbar="false"
                  :initData="false"
                  :randomRowKey="true"
                />
              </div>
            </div>
          </div>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :title="titleAnswer"
      :visible.sync="openAnswer"
      center
      width="1024px"
      append-to-body
      :close-on-click-modal="false"
      v-if="openAnswer"
    >
      <el-form ref="detailAnswerForm" :model="detailAnswerForm" :rules="rules" label-width="120px">
        <el-card class="form-card txnInfo-card">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原交易流水号" prop="oriId">
              <el-input v-model="detailAnswerForm.oriId" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailAnswerForm.id" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="报文标识号" prop="pkgId">
              <el-input v-model="detailAnswerForm.pkgId" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker
                v-model="detailAnswerForm.workdate"
                style="width: 100%"
                type="date"
                value-format="yyyyMMdd"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原报文标识号" prop="oriPkgId">
              <el-input v-model="detailAnswerForm.oriPkgId" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原发起参与机构" prop="oriSender">
              <el-input v-model="detailAnswerForm.oriSender" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原报文类型" prop="oriMsgType">
              <el-input v-model="detailAnswerForm.oriMsgType" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="业务状态" prop="bizStatus">
              <el-select
                style="width: 100%"
                v-model="detailAnswerForm.bizStatus"
                placeholder="业务状态"
                :disabled="true"
              >
                <el-option
                  v-for="dict in dictMap.PROCESSSTATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="业务拒绝处理码" prop="bizRejectCode">
              <el-select
                style="width: 100%"
                v-model="detailAnswerForm.bizRejectCode"
                placeholder="业务拒绝处理码"
                :disabled="true"
              >
                <el-option
                  v-for="dict in dictMap.CIS_CODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="业务拒绝信息" prop="bizRejectInfo">
              <el-input type="textarea" v-model="detailAnswerForm.bizRejectInfo" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="业务处理参与机构" prop="bizProOrg">
              <el-input v-model="detailAnswerForm.bizProOrg" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原扣款通知编号" prop="orgDbtNo">
              <el-input v-model="detailAnswerForm.orgDbtNo" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="付款人数目" prop="payerNum">
              <el-input v-model="detailAnswerForm.payerNum" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
          <div class="discountReceipt-pick-operate-box">
            <div class="operate-box-bottom">
              <div class="bottom-content">
                <ht-table
                  ref="dataTableAnswerDetail"
                  :multi-select="false"
                  :showSerialNumber="false"
                  :dictMap="dictMap"
                  :queryParams="queryParamsAnswerDetail"
                  :tableBindColumns="tableBindColumnsAnswerDetail"
                  :opButtonList="opButtonList"
                  :reqConfig="regConfigAnswerDetail"
                  :showRightToolbar="false"
                  :initData="true"
                />
              </div>
            </div>
          </div>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="cancelAnswer">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";
import {
  apiUrlConfigAnswerDetailQuery,
  apiUrlConfigDetailQuery,
  apiUrlConfigQuery,
  custAccDeductionQueryAnswerDetail,
  custAccDeductionQueryDetail,
} from "@/api/cnaps/beps/371";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";

export default {
  name: "CustAccDeductionQuery",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      // 查询参数
      queryParams: {
        id: undefined,
        workdate: undefined,
        workdate2: undefined,
      },
      queryParamsDetail: {
        id: undefined,
      },
      queryParamsAnswerDetail: {
        oriId: "",
      },
      loading: false,
      // 搜索
      defaultEventKey: "defaultEventKey",
      formOptions: [],
      //
      searchFormDictList: ["DebitManagementTypeCode", "RegionId", "CHECK_PROC_STATUS", "PROCESSSTATUS", "CIS_CODE"],
      // 列信息
      regConfig: apiUrlConfigQuery,

      regConfigDetail: apiUrlConfigDetailQuery,

      regConfigAnswerDetail: apiUrlConfigAnswerDetailQuery,

      tableBindColumns: [
        { prop: "id", label: "交易流水号", width: 180 },
        { prop: "workdate", label: "工作日期", type: "date", width: 120 },
        { prop: "pkgId", label: "报文标识号", width: 180 },
        { prop: "dbtMngType", label: "扣款管理类型", dictCode: "DebitManagementTypeCode", width: 120 },
        { prop: "dbtNo", label: "扣款通知编号", width: 120 },
        { prop: "regionId", label: "地域标识", dictCode: "RegionId", width: 120 },
        { prop: "uniformScCode", label: "统一社会信用代码", width: 180 },
        { prop: "payerNum", label: "付款人数目" },
      ],

      tableBindColumnsDetail: [
        { prop: "dbtDtlId", label: "扣款明细标识号", width: 180 },
        { prop: "payerName", label: "付款人名称", width: 120 },
        { prop: "payerAddr", label: "付款人地址", width: 120 },
        { prop: "payerActno", label: "付款人账号", width: 120 },
        { prop: "payerAccBrno", label: "付款人开户行行号", width: 180 },
        { prop: "payerBrno", label: "付款行行号", width: 120 },
        { prop: "curcd", label: "币种", width: 120 },
        { prop: "amount", label: "金额", type: "price"},
      ],

      tableBindColumnsAnswerDetail: [
        { prop: "dbtDtlId", label: "扣款结果明细标识号" },
        { prop: "dbtStatus", label: "扣款结果业务状态", dictCode: "CHECK_PROC_STATUS" },
      ],

      dictMapAsync: {},
      // 弹出层标题
      title: "",
      titleAnswer: "",
      // 是否显示弹出层
      open: false,
      openAnswer: false,
      // 表单参数
      detailForm: {},
      detailAnswerForm: {},

      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {},
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "查询日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
        case "answerdetail":
          this.handleAnswerDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    cancelAnswer() {
      this.openAnswer = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "客户账户扣款管理查询明细";
      custAccDeductionQueryDetail(row).then((response) => {
        this.detailForm = response.result;
        this.queryParamsDetail.id = response.result.id;
        this.open = true;
        this.$nextTick(() => {
          this.$refs.dataTableDetail.doQuery();
        });
      });
    },

    /** 详情按钮操作 */
    handleAnswerDetail(row) {
      this.titleAnswer = "客户账户扣款管理查询应答明细";
      custAccDeductionQueryAnswerDetail(row).then((response) => {
        this.detailAnswerForm = response.result;
        if (response.result.oriId !== null && response.result.oriId !== undefined) {
          this.queryParamsAnswerDetail.oriId = response.result.oriId;
        }
        this.openAnswer = true;
      });
    },
  },
};
</script>
